package wolftrace_company.study_android_ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import wolftrace_company.study_android_ui.R;
import wolftrace_company.study_android_ui.fragment.FragMentA;
import wolftrace_company.study_android_ui.fragment.FragMentB;
import wolftrace_company.study_android_ui.fragment.FragMentC;

/**
 * Created by SimpleTonOne on 2018/3/31.
 */

public class ShowFragActivity extends AppCompatActivity implements View.OnClickListener{
    private Button button1;
    private Button button2;
    private Button button3;
    private FragMentA fragMentA;
    private FragMentB fragMentB;
    private FragMentC fragMentC;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setContentView(R.layout.showfrag);
        button1 = findViewById(R.id.btn1);
        button2 = findViewById(R.id.btn2);
        button3 = findViewById(R.id.btn3);
        getSupportFragmentManager().beginTransaction().add(R.id.show_frag,new FragMentA()).commitAllowingStateLoss();
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn1:
                if (fragMentA==null)
                    fragMentA = new FragMentA();
                getSupportFragmentManager().beginTransaction().replace(R.id.show_frag,fragMentA).commitAllowingStateLoss();
                break;
            case R.id.btn2:
                if (fragMentB==null)
                    fragMentB = new FragMentB();
                getSupportFragmentManager().beginTransaction().replace(R.id.show_frag,fragMentB).commitAllowingStateLoss();
                break;
            case R.id.btn3:
                if (fragMentC==null)
                    fragMentC = new FragMentC();
                getSupportFragmentManager().beginTransaction().replace(R.id.show_frag,fragMentC).commitAllowingStateLoss();
                break;
        }
    }
}
